package com.taijia.chapter8;

import java.io.*;
import java.util.Date;

/**
 * Created by taijia on 2015/1/31.
 */
public class TestPrintStream3 {
    public static void main(String[] args) {
        String s = null;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        FileWriter fw = null;
        PrintWriter log = null ;
        try {
            fw = new FileWriter("E:/myeclipse2014/Workspaces/2014/msb_basic/src/com/taijia/chapter8/TestPrintStream3.txt", true); // log4j
            log = new PrintWriter(fw);
            while ((s = br.readLine()) != null) {
                if (s.equalsIgnoreCase("exit"))
                    break;
                System.out.println(s.toUpperCase());
                System.out.println("=====");
                log.println(s.toUpperCase());
                log.flush();// log 会自动flush
            }
            log.println("====" + new Date() + "====");
            log.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (log != null)
                log.close();
        }
    }
}
